<!Doctype html>
<html xmlns= http://www.w3.org/1999/xhtml>
<head>
    <meta http-equiv=Content-Type content="text/html;charset=utf-8">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <title>OpenLayers 3地图示例</title>
    <style>
        .navigate{
            padding: 4px;
            margin-top: 8px;
        }
    </style>
    <link href="lib/ol.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="lib/ol.js" charset="utf-8"></script>
</head>

<body>
<div id="map" style="width: 100%;height: 600px"></div>
<input type="button" class="navigate" value="左移" onclick="moveLeft()">
<input type="button" class="navigate" value="右移" onclick="moveRight()">
<input type="button" class="navigate" value="上移" onclick="moveUp()">
<input type="button" class="navigate" value="下移" onclick="moveDown()">
<input type="button" class="navigate" value="移到杭州" onclick="">
<input type="button" class="navigate" value="放大" onclick="zoomOut()">
<input type="button" class="navigate" value="缩小" onclick="zoomIn()">

<script>
    // 创建地图
  var map= new ol.Map({
        controls:ol.control.defaults({
            attributionOptions:({
                collapsible:true
            })
        }),
//        logo:false,
//        logo:'img/face_monkey.png',
        logo:{src:'img/face_monkey.png',href: 'http://www.openstreetmap.org/'},
        // 设置地图图层
        layers:[
            // 创建一个使用Open Street Map地图源的瓦片图层
            new ol.layer.Tile({source: new ol.source.OSM()})
        ],
        // 设置显示地图的视图
        view: new ol.View({
            center: ol.proj.transform([120.2, 30.26], 'EPSG:4326', 'EPSG:3857'),    // 定义地图显示中心于经度0度，纬度0度处
            zoom: 10           // 并且定义地图显示层级为2
        }),
        // 让id为map的div作为地图的容器
        target: 'map'
    });
       function moveLeft(){
           var view = map.getView();
           var center= view.getCenter();
           center[0]=center[0]+10000;
          view.setCenter(center);
           map.render();
       }
        function moveRight(){
            var view = map.getView();
            var center= view.getCenter();
            center[0]=center[0]-10000;
            view.setCenter(center);
           map.render();
        }
        function moveUp(){
            var view = map.getView();
            var center= view.getCenter();
            center[1]=center[1]-10000;
            view.setCenter(center);
           map.render();
        }
        function moveDown(){
            var view = map.getView();
            var center= view.getCenter();
            center[1]=center[1]+10000;
            view.setCenter(center);
           map.render();
        }
        function zoomOut(){
            var view = map.getView();
            var zoom = view.getZoom();
            view.setZoom(zoom+1);
        }
        function zoomIn(){
            var view = map.getView();
            var zoom = view.getZoom();
            view.setZoom(zoom-1);
        }

</script>
</body>

</html>